package com.kasax.android.arch.base.ui;

import android.view.View;
import android.widget.FrameLayout;

import androidx.activity.EdgeToEdge;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.kasax.android.arch.utils.LogUtils;

public abstract class BaseCompatActivity extends BaseActivity {

    private View normalMainView;

    @Override
    protected void injectBeforeSetContentView() {
        try {
            EdgeToEdge.enable(this);
        } catch (Exception e) {
            LogUtils.e(e.getMessage());
        }
        normalMainView = new FrameLayout(this);
    }

    @Override
    protected void injectBeforeInitView() {
        try {
            View mainContentView = getMainContentView();
            if (mainContentView != null) {
                ViewCompat.setOnApplyWindowInsetsListener(mainContentView, (v, insets) -> {
                    Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
                    v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
                    return insets;
                });
            }
        } catch (Exception e) {
            LogUtils.e(e.getMessage());
        }
    }

    protected View getMainContentView() {
        return getNormalView();
    }

    /**
     * 默认是空的view
     *
     * @return
     */
    private View getNormalView() {
        return normalMainView;
    }
}
